#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
// 使用带参数的宏处理全局错误处理-推荐
#define handle_error2(res,msg) \
          if(res==-1){\
            perror(msg);\
            exit(EXIT_FAILURE);\
          }     

// 自定义错误处理函数
void handle_error1(int res,char *msg){
  if(res==-1){
    perror(msg);
    exit(EXIT_FAILURE);
  }
}

int main(void){
  int fd = open("text.txt",O_RDONLY);
  //handle_error1(fd,"open");
  handle_error2(fd,"open");
  return 0;
}
